/* Copyright (c) 2016-2020 Enfry Ltd. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of Enfry. 
 * You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with Enfry.
 */
package com.enfry.common.util.control;

import java.util.List;

/**
 * 
 * <请简单说明此类用途>
 * 
 * @Title com.enfry.util.control.Eventee
 * @author Penghu
 * @date 2018年1月10日
 */
public class Eventee<E> implements Runnable {
	private E event;
	private List<Eventer<E>> eventerList;

	public Eventee() {

	}

	public Eventee(E event) {
		this.event = event;
	}

	public Eventee(E event, List<Eventer<E>> eventerList) {
		this.event = event;
		this.eventerList = eventerList;
	}

	public void run() {
		for (Eventer<E> eventer : eventerList) {// 按注册顺序冒泡处理
			if (!eventer.process(event))
				break;
		}
	}

	public E getEvent() {
		return event;
	}

	public List<Eventer<E>> getEventerList() {
		return eventerList;
	}

	public int hasCode() {
		return event.hashCode();
	}

	public boolean equals(Object obj) {
		if (obj == null)
			return false;

		if (!(obj instanceof Eventee<?>))
			return false;

		Eventee<?> other = (Eventee<?>) obj;
		if (other.event == null)
			return this.event == null;
		else
			return (other.event.equals(this.event));
	}

	public String toString() {
		return event.toString();
	}
}
